#include <iostream>
using namespace std;

const int N = 20; //行列的最大值是10
const int M = 30; //步数的最大值是20
const int dx[4] = {0, 0, 1, 1};
const int dy[4] = {0, 1, 0, 1}; //相当于是左左，下左，左下，下下

int n;
int a[N][N];
int x, y, z; //获取三元组
int f[M][N][N];

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> n;
    while (cin >> x >> y >> z, x || y || z)
        a[x][y] = z;
    f[2][1][1] = a[1][1]; //初始化起点
    for (int k = 3; k <= 2 * n; ++k)
        for (int i_1 = 1; i_1 < k; ++i_1)
            for (int i_2 = 1; i_2 < k; ++i_2)
                if (i_1 != i_2)
                    for (int i = 0; i < 4; ++i)
                        f[k][i_1][i_2] = max(f[k][i_1][i_2], f[k - 1][i_1 - dx[i]][i_2 - dy[i]] + a[i_1][k - i_1] + a[i_2][k - i_2]);
                else
                    for (int i = 0; i < 4; ++i)
                        f[k][i_1][i_2] = max(f[k][i_1][i_2], f[k - 1][i_1 - dx[i]][i_2 - dy[i]] + a[i_1][k - i_1]); //相等就只拿一个就好啦
    cout << f[2 * n][n][n];
    return 0;
}